package com.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class SpringRedict {
	@RequestMapping("/hello")
	public void hello(HttpServletRequest req,HttpServletResponse rep) throws IOException, ServletException{
		//rep.getWriter().println("this is an example for redict.");
	    
		//实现重定向
		//rep.sendRedirect("index.jsp");
		
		//实现转发
		req.setAttribute("msg", "servlet api forward");
		req.getRequestDispatcher("index.jsp").forward(req, rep);
	}
	
	@RequestMapping("/hello1")
	public String hello(){
		//转发1
		//return "index.jsp";
		
		//转发2
	    //return "forward:index.jsp";
	    
	    //重定向
	    return "redirect:index.jsp";
	}
	
	@RequestMapping("/hello2")
	public String hello2(){
		return "hello";  //返回路径/web-inf/jsp,需要在mvc.xml里配置视图解析器。
	}
}
